package com.ruoyi.web.controller.examine;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.examine.domain.TbDormitoryInspection;
import com.ruoyi.examine.service.ITbDormitoryInspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 宿舍检查Controller
 *
 * @author ruoyi
 * @date 2023-12-27
 */
@RestController
@RequestMapping("/examine/inspection")
public class TbDormitoryInspectionController extends BaseController
{
    @Autowired
    private ITbDormitoryInspectionService tbDormitoryInspectionService;

    /**
     * 查询宿舍检查列表
     */
    @PreAuthorize("@ss.hasPermi('examine:inspection:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbDormitoryInspection tbDormitoryInspection)
    {
        startPage();
        List<TbDormitoryInspection> list = tbDormitoryInspectionService.selectTbDormitoryInspectionList(tbDormitoryInspection);
        return getDataTable(list);
    }

    /**
     * 导出宿舍检查列表
     */
    @PreAuthorize("@ss.hasPermi('examine:inspection:export')")
    @Log(title = "宿舍检查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDormitoryInspection tbDormitoryInspection)
    {
        List<TbDormitoryInspection> list = tbDormitoryInspectionService.selectTbDormitoryInspectionList(tbDormitoryInspection);
        ExcelUtil<TbDormitoryInspection> util = new ExcelUtil<TbDormitoryInspection>(TbDormitoryInspection.class);
        util.exportExcel(response, list, "宿舍检查数据");
    }

    /**
     * 获取宿舍检查详细信息
     */
    @PreAuthorize("@ss.hasPermi('examine:inspection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbDormitoryInspectionService.selectTbDormitoryInspectionById(id));
    }

    /**
     * 新增宿舍检查
     */
    @PreAuthorize("@ss.hasPermi('examine:inspection:add')")
    @Log(title = "宿舍检查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDormitoryInspection tbDormitoryInspection)
    {
        return toAjax(tbDormitoryInspectionService.insertTbDormitoryInspection(tbDormitoryInspection));
    }

    /**
     * 修改宿舍检查
     */
    @PreAuthorize("@ss.hasPermi('examine:inspection:edit')")
    @Log(title = "宿舍检查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDormitoryInspection tbDormitoryInspection)
    {
        return toAjax(tbDormitoryInspectionService.updateTbDormitoryInspection(tbDormitoryInspection));
    }

    /**
     * 删除宿舍检查
     */
    @PreAuthorize("@ss.hasPermi('examine:inspection:remove')")
    @Log(title = "宿舍检查", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbDormitoryInspectionService.deleteTbDormitoryInspectionByIds(ids));
    }
}
